package demo6;

// 最长回文子序列
/*
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        int n = str.length();
        int[][] dp = new int[n+1][n+1];
        for(int i = 0; i<n; i++) {
            dp[i][i] = 1;
        }

        for(int j = 1; j<n; j++) {
            for(int i = j-1; i>=0; i--) {
                if(str.charAt(i) == str.charAt(j)) {
                    if(i+1 == j) {
                        dp[i][j] = 2;
                    }else {
                        dp[i][j] = dp[i+1][j-1] + 2;
                    }
                }else {
                    if(i+1 >= j) {
                        dp[i][j] = 1;
                    }else {
                        dp[i][j] = Math.max(dp[i+1][j], dp[i][j-1]);
                    }
                }
            }
        }

//        System.out.print("  ");
//        for(int i = 0; i<n; i++) {
//            System.out.print(i+" ");
//        }
//        System.out.println();
//        for(int i =  0; i<n; i++) {
//            System.out.print(i + " ");
//            for(int j = 0; j<n; j++) {
//                System.out.print(dp[i][j] + " ");
//            }
//            System.out.println();
//        }
//        System.out.println(dp[0][n-1]);
    }
}

/*

abccsb
111214
dp[i][j]: str中 i~j 之间的最长回文子序列的长度
*/


import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        int n = str.length();
        int[][] dp = new int[n+1][n+1];
        for(int i = 0; i<n; i++) {
            dp[i][i] = 1;
        }

        for(int j = 1; j<n; j++) {
            for(int i = j-1; i>=0; i--) {
                if(str.charAt(i) == str.charAt(j)) {
                    if(i+1 == j) {
                        dp[i][j] = 2;
                    }else {
                        dp[i][j] = dp[i+1][j-1] + 2;
                    }
                }else {
                    dp[i][j] = Math.max(dp[i+1][j], dp[i][j-1]);
                }
            }
        }
        System.out.println(dp[0][n-1]);
    }
}
